#ifndef ONLINE_UPDATE_H
#define ONLINE_UPDATE_H
#include "include.h"

/**************************************************************************
| 0x08000000 | 0x08010000 |  0x08020000   |  0x08040000   |  0x08060000   |
---------------------------------------------------------------------------
|    BOOT    |  SETTING   |      APP1     |      APP2     |      APP3     |
---------------------------------------------------------------------------
|    64K     |     64K    |      128K     |      128K     |      128K     |
***************************************************************************/

/*
APP1 : 工作区

APP2 : 暂存区

APP3 : 备份区
*/

typedef enum
{
    NONE,
    Start_APP1,
    Recv_New_APP_To_APP2,
    Copy_APP2_To_APP1,
    Copy_APP3_To_APP1,
    BUSY,
} PRPCESS_STATUS;

typedef struct
{
  uint8_t  flash_readdata[3];
  uint16_t target_id;
  uint16_t this_id;
  uint16_t split_size;
  uint16_t split_count;
  uint16_t this_count;
  uint16_t this_size;
  uint16_t last_count;
  uint8_t  data[1024];
  uint8_t  error_type;
  uint16_t now_count;
  uint8_t  app1_start_count;
}__attribute__((packed, aligned(1)))  IAP_BTLD;

extern PRPCESS_STATUS process;
extern IAP_BTLD       iap_btld;
void set_bootloader_copy_app3_to_app1( void );
void recv_bin_handle( uint8_t *data, uint16_t size );
void start_bootloader_recv_bin( uint8_t *data );
void bootloader_prepare( void );
void bootloader( void );
#endif